//
//  CPSCServiceTableViewV2Cell.m
//  CollTest
//
//  Created by codew on 11/24/21.
//

#import "CPSCServiceTableViewV2Cell.h"
#import "CPSCVerticalAndTransverseMarkView.h"
#import "CPSCMarkAttributedStringTools.h"

#define KValueWidthLeftSuper 58

@interface CPSCServiceTableViewV2Cell ()

// Left ============================================
@property (weak, nonatomic) IBOutlet UIImageView *imageViewIcon;
@property (weak, nonatomic) IBOutlet UIView *viewVerticalSuper;
@property (weak, nonatomic) IBOutlet UIView *viewTransverseSuper;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *widthLeftSuper;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *heightlblTitleSuper;


/** 现卖价 */
@property (weak, nonatomic) IBOutlet UILabel *lblCurrentPrice;

// 单位
@property (weak, nonatomic) IBOutlet UILabel *lblUnitCurrentPrice;

/** 原价 */
@property (nonatomic, strong) IBOutlet UILabel * lblOriginalPrice;



@property (nonatomic, strong) CPSCVerticalAndTransverseMarkView * viewMarkVertical;
/** 横向标签 */
@property (nonatomic, strong) CPSCVerticalAndTransverseMarkView * viewMarkTransverse;
@property (weak, nonatomic) IBOutlet UILabel *lblTitle;



@end


@implementation CPSCServiceTableViewV2Cell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    self.widthLeftSuper.constant = KValueWidthLeftSuper;
    
    
    self.imageViewIcon.layer.cornerRadius = KValueWidthLeftSuper * 0.5;
    self.imageViewIcon.layer.masksToBounds = YES;
    self.lblTitle.font = [UIFont boldSystemFontOfSize:16];
    
    
    self.lblCurrentPrice.font = [UIFont boldSystemFontOfSize:18];
    self.lblUnitCurrentPrice.font = [UIFont boldSystemFontOfSize:11];
    
    
    self.heightlblTitleSuper.constant = 66;
    [self initSubviews];
    [self makeContraints];
        
}


- (void)initSubviews
{
//    self.viewMarkVertical.frame = CGRectMake(0, 0, self.widthLeftSuper.constant, 300);
    [self.viewVerticalSuper addSubview:self.viewMarkVertical];
    [self.viewTransverseSuper addSubview:self.viewMarkTransverse];
    [self deBugUI];
}

- (void)makeContraints {
 
    [self.viewMarkVertical mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(8);
        make.left.right.bottom.mas_equalTo(0);
    }];
    
    [self.viewMarkTransverse mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.bottom.mas_equalTo(0);
    }];


}

- (void)deBugUI
{
    //    self.viewHtmlContentSuper.backgroundColor = kCPSCRandomColor;
    //    self.lblContent.backgroundColor = kCPSCRandomColor;
    
    NSArray *arrPrice = @[
    
        @"1000",
        @"6888",
        @"10%",
        @"88",
        @"568"
    ];
    
    NSArray *arrUnit = @[
    
        @"服务费起",
        @"元"
    ];
    
    NSArray * titleArr = @[
    
        @"牛逼",
        @"牛叉哄哄",
        @"你猜",
        @"你叉叉",
    ];
    NSArray * titleArr2 = @[
    
        @"牛逼",
        @"牛叉哄哄",
        @"你猜",
        @"你叉叉",
        @"牛逼",
        @"牛叉哄哄",
        @"你猜",
        @"你叉叉",
        @"牛逼",
        @"牛叉哄哄",
        @"你猜",
        @"你叉叉",
        @"牛逼",
        @"牛叉哄哄",
        @"你猜",
        @"你叉叉",
    ];
    
    
    NSArray * dataIcon = @[
    
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic2.zhimg.com%2F50%2Fv2-f4d373f0b1ad3692c9e495ab100c0821_hd.jpg&refer=http%3A%2F%2Fpic2.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297619&t=8da02b70889b853cbff433200f70a216",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp9.itc.cn%2Fq_70%2Fimages03%2F20200703%2F7cd179c31d574924a3fa110185791bb7.jpeg&refer=http%3A%2F%2Fp9.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297663&t=8005f4718f4be98be11b9798d94b5335",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fp9.itc.cn%2Fq_70%2Fimages03%2F20200619%2Fa0c3dba1de29443987b68a72145b3382.jpeg&refer=http%3A%2F%2Fp9.itc.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297732&t=34ed5c5c5d78c46e4ca577b0c6ee169f",
        
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fb-ssl.duitang.com%2Fuploads%2Fitem%2F201807%2F12%2F20180712170406_L8yah.thumb.700_0.png&refer=http%3A%2F%2Fb-ssl.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297725&t=0624fc350375eea06391b6099b5dc6f5",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fqqpublic.qpic.cn%2Fqq_public%2F0%2F0-2309376679-3367A8C62AA2C4FED37AEDA07FD2336A%2F0%3Ffmt%3Djpg%26size%3D26%26h%3D441%26w%3D440%26ppv%3D1.jpg&refer=http%3A%2F%2Fqqpublic.qpic.cn&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297711&t=ed91fa7eac34734fa511266fb2ffb409",
        
        @"https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fpic3.zhimg.com%2F50%2Fv2-2bdb993d9d4069605c24d9af019e8723_hd.jpg&refer=http%3A%2F%2Fpic3.zhimg.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1639297853&t=cfc6f253dbdc642fef7479693b73a424"
        
    ];
    
    
    [self.viewMarkVertical updateVerticalViewWithTitles:titleArr];
    
    [self.viewMarkTransverse updateTransverseViewWithTitles:titleArr2];
    
    NSInteger index = arc4random_uniform(dataIcon.count);
    NSString * imageUrl = dataIcon[index];
    NSString * url = imageUrl;
    
    [self.imageViewIcon sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"default_img_list"]];
    
    index = arc4random_uniform(3);
    
    UIImage * image;// = [UIImage imageNamed:@"category_mark_sc"];
    CGRect imageBounds;
    /**  活动类型（1：限时抢购 2：秒杀，3：限量抢购）    */
    if (index == 1) {
        
        image = [UIImage imageNamed:@"category_mark_t"];
        imageBounds = CGRectMake(0, -2.5, 46, 16);
    }else if (index == 2){
        
        // 秒杀
        image = [UIImage imageNamed:@"category_mark_sc"];
        imageBounds = CGRectMake(0, -2.5, 26, 16);
        
    }else{
//        image = [UIImage imageNamed:@"category_mark_sc_t"];
//        imageBounds = CGRectMake(0, -2.5, 46, 16);
    }
    
    NSString * titile = @"更精确的保证双平台的一致性。面向 Google 以及 Stack Overflow 编程了一会后发现，能查到的资料大部分是介绍如何实现 lineSpacing 属性，而不是 lineHeight。但是我就是因为 iOS 和 Android 的默认 lineSpacing 不一致所以才想实现个 lineHeight 啊！还是需要自己动手丰衣足食";
    
    NSMutableAttributedString * titleLabAttributedString = [CPSCMarkAttributedStringTools attributedStringWithMarkImage:image imageBounds:imageBounds contentText:titile lineSpacingValue:6];
    self.lblTitle.attributedText = titleLabAttributedString;
    
    
    //--------
    NSInteger indexC = arc4random_uniform(arrPrice.count);
    NSString * arrPriceS = arrPrice[indexC];
    self.lblCurrentPrice.text = arrPriceS;
    
    // ------
    NSInteger indexUnit = arc4random_uniform(arrUnit.count);
    NSString * arrUnitS = arrUnit[indexUnit];
    self.lblUnitCurrentPrice.text  = arrUnitS;
    
    
    self.lblOriginalPrice.attributedText = [CPSCMarkAttributedStringTools
                                            attributedStringOriginalPrice:arrPrice[arc4random_uniform(arrPrice.count)]
                                            unitString:arrUnit[arc4random_uniform(arrUnit.count)]
                                            lineContainUnit:YES];
    
    
}

- (void)updateCellWithItem:(id)item
{
 
    
    
    
    
    
    // 省略号
    self.lblTitle.lineBreakMode = NSLineBreakByTruncatingTail;
}
#pragma mark - Getter Setter
#pragma mark - Getter Setter

- (CPSCVerticalAndTransverseMarkView *)viewMarkVertical
{
    if (!_viewMarkVertical) {
        _viewMarkVertical = [[CPSCVerticalAndTransverseMarkView alloc] init];
    }
    return _viewMarkVertical;
}

- (CPSCVerticalAndTransverseMarkView *)viewMarkTransverse
{
    if (!_viewMarkTransverse) {
        
        _viewMarkTransverse = [[CPSCVerticalAndTransverseMarkView alloc] init];
        _viewMarkTransverse.clipsToBounds = YES;
    }
    return _viewMarkTransverse;
}
@end
